1. Field of the Invention
This invention relates to computer systems, and more particularly, to methods and apparatus for caching data representing the texture of surfaces to be displayed by a computer.
2. History of the Prior Art
In three dimensional graphics, surfaces are typically rendered by assembling a plurality of polygons into a desired shape. The polygons are conventionally triangles having vertices which are defined in world space by three dimensional distance coordinates, by color values, and by texture coordinates. The color values define the brightness of each of red/green/blue (r, g, b) colors at each vertex and thus the color at each vertex. The texture coordinates (u, v) define the coordinates of each vertex on a texture map defined by values stored in memory. Other characteristics such as transparency, fog, spectral colors, and additional textures may also define each vertex in a particular system to provide more sophisticated rendering.
It has been the practice that an application program executing on a central processor provides to a graphics accelerator the coordinates and attributes of the vertices of each triangle which is to be included in the shape being assembled for display. The surfaces represented by an assembly of polygons are, as a generality, being viewed in perspective.
Typically, the application furnishes the horizontal (x) and vertical (y) distance coordinates as screen values. If instead the application furnishes the distance coordinates as world space values, then these values should, for proper display, be transformed into screen coordinates by a perspective transformation process. Along with the distance coordinates, the application typically furnishes the color values, the texture coordinates, and other attributes of the vertices as world space values. If the x and y screen coordinates of the vertices are known, the pixels defining a triangle on the screen may be determined. Then, the world space depth values (z), the color values, and the texture coordinates may be used to determine the depth value, the color values, and the texture coordinates for each pixel.
In order to provide perspective-correct values for each of the various attributes of a pixel to be displayed, the world space values of these attributes should be transformed into screen values. The vertices of a triangle define a plane in world space so the depth of positions in the triangle vary linearly from one vertex to the other within the triangle in world space. This allows the depth value for each position in the triangle in world space to be determined by a linear interpolation process. If the depth at any position in the triangle can be known, then the depth of each pixel which defines the triangle on the screen may be determined by perspective transformation of the world space depth values.
Similarly, the color values and the texture coordinates for each pixel defining the triangle vary linearly from vertex to vertex in world space; and the same type of linear interpolation process and perspective transformation could be used to find the color values and texture coordinates for each pixel in screen space.
Once the depth value, color values, and texture coordinates for each pixel have been determined, the texture coordinates could be utilized to determine texture values from the related texture map; and these texture values could then be utilized to modify the color values of each pixel in the triangle.
Although, all of this is conceivable, the prior art has not provided hardware to accomplish these processes because of the very large number of steps required and the time necessary to accomplish those steps. Instead, most of the attributes provided by an application program are simply treated as though they are screen coordinates. This provides colors and other attributes which may be somewhat distorted but useable. However, texture patterns are so distorted by such a compromise that they are unusable.
A texture map is a matrix of values which describe a pattern to be applied to the surface of the triangle to vary the colors in accordance with the pattern. Sets of texture coordinates u and v each indicate a particular texture value (texel) in a texture map and allow that texel to be accessed. The texture coordinates of the vertices of a triangular surface area thus define the position of the triangle on the texture map so that the texels within the triangle determine the texture applied to each portion of the surface of the triangle. Each individual screen pixel describing the triangle covers some portion of the texture map as the triangle is projected onto the screen.
Screen texture coordinates obtained by the linear interpolation and perspective projection processes are not typically integral values. On the other hand, indexing into a texture map is accomplished using integral coordinates. Consequently, non-integral coordinates obtained by interpolation and perspective projection must somehow be used to obtain texture values. A simple method of obtaining texture values uses the closest integral u and v values for each pixel to index into the texture map and then selects the texture value at that intersection. A more accurate method of determining a texture value called bilinear interpolation utilizes the integer portion of the u and v coordinates at the center of each pixel to determine four additional sets of integral coordinates defining positions on a texture map surrounding the pixel center. The process selects the texels at these four positions and then uses the fractional portion of the texture coordinates at the pixel center to weight the texture values surrounding the index point. The four weighted texture values are combined into a more accurate representation for modifying the color values of that pixel to reproduce the texture pattern.
Those skilled in the art have recognized that where a pixel covers a very large number of texture values on a texture map, only a small portion of those values will be represented in the final texture value selected to modify the color of that pixel using the methods described. Consequently, a more accurate method of texture mapping has been devised which provides texture maps at a plurality of different scales. A proper scale can be chosen so that the pixels defining the individual triangles may be made to cover numbers of texels in the projection of the texture map in screen space which accurately reproduce the texture value. The process of selecting a texture value for a pixel then includes an initial step for each particular triangle being rendered in which a texture map is selected having a scale adapted to accurately represent texture values for the pixels of that triangle. This selection may include an additional process of selecting scales above and below a desired scale and interpolating between those scales to reach a final scale.
Although these methods provide progressively more accurate texture values for pixels if the triangle lies in a plane parallel to the screen surface, they are all based on the assumption that the projection of a pixel onto the texture map is square or rectangular in shape. This assumption is incorrect in the greater number of cases when three dimensional shapes are being rendered. In fact, none of these methods is capable of describing with sufficient accuracy the texture values which should be attributed to the pixels when three dimensional shapes are rendered in any significant perspective on a flat screen surface.
Because of this, additional processes are being developed which include methods for determining texture values at a greater plurality of points within a pixel all of which points are positioned with regard to both the shape of the pixel and the shape of the texture map. In such methods, texture values are determined at each of these plurality of points (or at four points surrounding each point of this plurality of points) within a projected pixel and the values blended into a single final texture value.
As may be seen, the process of determining texture values for pixels is very complex and requires very large numbers of texels for many triangles. Whatever process is used to determine accurate texture values, it is first necessary to transfer this very large number of texture values from memory to the graphics accelerator circuitry so that these texture values may be utilized in the determination of a final texture value for each pixel in the triangle.
Conventionally, the data defining the texture values for each triangle are individually transferred by the central processing unit to the graphics accelerator via the system input/output bus. This requires that the central processing unit gain access to the system bus through the bus control circuitry, send the data for a first texture value, regain control of the bus to send data regarding a second texture value, and so on. Typically, it takes a great number of bus accesses to send the texture value data for each pixel in a single triangle. As will be appreciated, this is a relatively slow process. To date, the process has been acceptable because graphics accelerators have been too slow to handle the data provided by the central processing unit. However, at least one graphics accelerator has become fast enough to handle more data than the central processing unit is capable of transferring in this manner.
To cut down on bus transit time, many graphics accelerators now utilize very large amounts of local storage on the graphics accelerator and move as many texture maps as possible to that storage. These accelerators then utilize a processor on the graphics accelerator board to access this secondary memory and thereby reduce bus transit time. However, even though these accelerators often provide eight or sixteen megabytes of data storage some part of which may be used for caching textures, this secondary memory must still be accessed in the same manner that main memory is accessed to transfer the texture values to a texture engine where the texture values are manipulated to produce a final texture value for each pixel. Even this local memory access is significantly slower than desirable.
A recent graphics accelerator has overcome this problem by providing a texture cache for texels in addition to local storage for texture maps. The cache may be accessed much more rapidly than either local memory or system memory, and its use therefore significantly accelerates the operation of the graphics pipeline. For example, if cache access requires one interval of time, then access of a texture map in local memory may require thirty-two to sixty-four times that interval; and access of a texture map in local memory may require sixty-four to one hundred twenty-eight times that interval. In one embodiment, such a cache is usually capable of storing all of the texels to be used in defining a texture value for each pixel of a particular graphics primitive and to have those texels available for computation of a texture value as each pixel is rendered. Such a texture cache is described in detail in U.S. patent application Ser. No. 09/056,656, entitled Texture Cache For A Computer Graphics Accelerator, filed Apr. 7, 1998, and assigned to the assignee of the present invention.
One problem that has been encountered in utilizing such a texture cache is that there are times when the texel data is not available in the texture cache. For example, when a new texture is first applied to a triangle, the texels are not yet available in the cache. Similarly, since a cache must have a finite size, often all of the texture data needed for any triangle cannot be stored in the cache. Consequently, If the texture data is not in the cache, then the graphics pipeline must stall until the data is retrieved from local or system memory. The result is that significant delays in the graphics rendering pipeline occur.
It is desirable to provide apparatus and a method for more rapidly providing data defining texture values for use by graphics accelerator circuitry.